<?php

namespace app\common\model\Business;

use think\Model;
use think\Request;

class Likes extends Model
{
    //指定模型可操作的表名
    protected $name = "teacher_follow";

    //也可以写$table,但此时要加表前缀 
    //protected $table ="fa_subject_teacher"

    //指定自动插入时间戳
    protected $autoWriteTimestamp = true;

    //指定插入时间戳的字段
    protected $createTime = "createtime";

    //更新时间戳时不进行写入操作
    protected $updateTime = false;

    //忽略数据表中不存在的字段
    protected $field = true;

    protected $append = [
        'createtime_text',
    ];
    
    public function getCreatetimeTextAttr($value,$data)
    {
        //获取数据
        $createtime = isset($data['createtime']) ? trim($data['createtime']) : '';

        if(empty($createtime))
        {
            return '暂无时间';
        }
        return date('Y-m-d',$createtime);
    }
    
    //关联查询
    public function teacher()
    {
       return $this->belongsTo('app\common\model\Teacher\Teacher','teacherid','id',[],'LEFT')->setEagerlyType(0);
    }

    public function business()
    {
        return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


   
}
